package test;


import java.util.LinkedList;
import java.util.Stack;

public class Main2 {

    public static void main(String[] args) {
        int[] array = new int[]{5, 7, 4, 1, 2, 5, 15, 4, 8, 5, 6, 5, 1, 4, 8, 2, 1, 4, 5, 2, 0, 45, 2};
        quickSort(array);
        for (int i : array) {
            System.out.print(i + ",");
        }
    }
    /**
     * 快速排序
     */
    public static void quickSort(int[] array) {
        if (array == null || array.length == 0) {
            return;
        }
        quickSort(array, 0, array.length - 1);
    }

    public static void quickSort(int[] array, int start, int end) {
        if (start >= end) {
            return;
        }
        int low = start;
        int high = end;
        int p = array[start];
        while (low < high) {
            while (low < high && array[high] >= p) {
                high--;
            }
            while (low < high && array[low] <= p) {
                low++;
            }
            swap(array, low, high);
        }
        swap(array, low, start);
        quickSort(array, start, low - 1);
        quickSort(array, low + 1, end);
    }

    public static void swap(int[] array, int s, int t) {
        int temp = array[s];
        array[s] = array[t];
        array[t] = temp;
    }

}
